#ifndef _MEMBER_BSTYLEDOCUMENT_H_
#define _MEMBER_BSTYLEDOCUMENT_H_

#include <BMap>
#include <BTable>
#include <BIcon>
#include <BImage>
#include <BString>
#include <BWidget>
#include <BStyleDocument>
#include "member_BStyle.h"

#define styledoc_member(styledoc)		((member_BStyleDocument*)((BStyleDocument*)styledoc)->_ptr)

namespace BWE
{
	class member_BStyleDocument
	{
		friend class BStyleDocument;
	public:
		member_BStyleDocument(BStyleDocument* styleDocument);
		~member_BStyleDocument();

		void read(BStyle* style, const BString& text, int& pos);
		void write(const BStyle* style, BString& text, int level);

		BString& errorMessage();
		BString& warningMessage();

	protected:
		bool readComment(const BString& text, int& pos, BString& comment);
		BStyle* findChild(BString& text, BStyle* style);
		BStyle* addStyle(BString& text, BStyle* parent);
		BStyle* addAnnex(BString& text, int pos, BStyle* style);
		void readDesc(BString& text, BStyle* style);
		void analysis(BString& sign, BString& value, BStyle* style);

		void analysisTitle(BStyle* style, BString& sign, BString& value);
		void analysisText(BStyle* style, BString& sign, BString& value);
		void analysisBackground(BStyle* style, BString& sign, BString& value);
		void analysisForeground(BStyle* style, BString& sign, BString& value);
		void analysisBorder(BStyle* style, BString& sign, BString& value);
		void analysisPerch(BStyle* style, BString& sign, BString& value);
		void analysisMargin(BStyle* style, BString& sign, BString& value);
		void analysisRadius(BStyle* style, BString& sign, BString& value);
		void analysisFont(BStyle* style, BString& sign, BString& value);
		void analysisArea(BStyle* style, BString& sign, BString& value);
		void analysisScroll(BStyle* style, BString& sign, BString& value);
		void analysisSpread(BStyle* style, BString& sign, BString& value);
		void analysisChunk(BStyle* style, BString& sign, BString& value);

		void analysisGroove(BStyle* style, BString& sign, BString& value);
		void analysisIcon(BStyle* style, BString& sign, BString& value);
		void analysisImage(BStyle* style, BString& sign, BString& value);
		void analysisFixed(BStyle* style, BString& sign, BString& value);
		void analysisMin(BStyle* style, BString& sign, BString& value);
		void analysisMax(BStyle* style, BString& sign, BString& value);
		void analysisArrow(BStyle* style, BString& sign, BString& value);
		void analysisHandle(BStyle* style, BString& sign, BString& value);
		void analysisWire(BStyle* style, BString& sign, BString& value);
		void analysisSelection(BStyle* style, BString& sign, BString& value);
		void analysisIndicator(BStyle* style, BString& sign, BString& value);
		void analysisGridLine(BStyle* style, BString& sign, BString& value);
		void analysisLine(BStyle* style, BString& sign, BString& value);

		void resourceValue(BStyle* style, BString& sign, BString& value);
		void resourceColor(BStyle* style, BString& sign, BString& value);
		void resourceImage(BStyle* style, BString& sign, BString& value);
		void resourceIcon(BStyle* style, BString& sign, BString& value);
		void resourceText(BStyle* style, BString& sign, BString& value);
		void resourceWord(BStyle* style, BString& sign, BString& value);
		void resourceTrans(BStyle* style, BString& sign, BString& value);

		bool readColor(BString& value, BColor& color);
		bool assignMultiImage(BStyle* style, StyleImage name, const BString& fileName);
		bool readMultiImage(const BString& fileName, BMap<State, BImageHolder>& imageMap);
		BImage* readImage(const BString& fileName);
		BIcon* readIcon(const BString& fileName);

		void assemble(BString& text, int name, const BValue& value);
		void assembleString(BString& text, const char* sign, const BValue& value);
		void assembleBool(BString& text, const char* sign, const BValue& value);
		void assembleInt(BString& text, const char* sign, const BValue& value);
		void assembleFloat(BString& text, const char* sign, const BValue& value);
		void assembleDouble(BString& text, const char* sign, const BValue& value);
		void assembleSize(BString& text, const char* sign, const BValue& value);
		void assembleIcon(BString& text, const char* sign, const BValue& value);
		void assembleImage(BString& text, const char* sign, const BValue& value);
		void assembleColor(BString& text, const char* sign, const BValue& value);
		void assmbleGridStyle(BString& text, const char* sign, const BValue& value);
		void assembleGraph(BString& text, const char* sign, const BValue& value);
		void assembleForm(BString& text, const char* sign, const BValue& value);
		void assembleAlign(BString& text, const char* sign, const BValue& value);

	private:
		BStyleDocument*				boss;
		BString						path;
		int							lineNumber;
		int							linePos;
		bool						error;
		BValue						message;
		BString						colorStr;
		BMap<BString, BImageHolder>	imageMap;
	};
}

#endif